#include <iostream>

using namespace std;

const int N = 1e5 + 10;
int n;
int a[N];
int main()
{
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> a[i];
    int res = 0;
    for(int i = 0;i < n;i ++)
    {
        if(i == a[i]) res++;
    }
    if(res == n) cout << n << endl;
    else
    {
        for(int i = 0;i < n;i ++)
        {
            if(a[i] != i && a[a[i]] == i)
            {
                cout << res + 2 << endl;
                return 0;
            }
        }
        cout << res + 1 << endl;
    }
    return 0;
}